package lily.phs.urh;

import lily.phs.object.HealthTest;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 健康体检表（Page 3）的界面布局和数据处理封装的view类
 * @author heckassitant
 *
 */
public class HealthTest_3 extends LinearLayout implements OnClickListener, OnFocusChangeListener{

//	private MyPopupWindow mPopupWindow;
	private Context mContext;
	private int profileid = 0;
	private int testid = 0;
	private EditText et_tenderness,et_mess,et_hepatomegalia,et_splenoma,et_shift_dullness,et_anus_other,et_mammary_gland_other,et_vulva_abnormal,
	                 et_vagina_abnormal,et_cervix_abnormal,et_palace_abnormal,et_appendix_abnormal,et_bodycheck_other,et_hemoglobin,et_wbc,
	                 et_blood_platelet,et_blood_other,et_pro,et_glu,et_urine_ketone,et_bld,et_urine_other,et_fbs_1,et_fbs_2,et_ecg,et_uae,et_ghb;
	
	private RadioGroup rgTenderness,rgMess,rgHepatomegalia,rgSplenoma,rgShiftDullness,rgLowerlimbEdema,rgAnus,
	                   rgVulva,rgVagina,rgCervix,rgPalace,rgAppendix,rgEcg,rgFecalOccultBlood;
	private RadioButton rb_tenderness_1,rb_tenderness_2,rb_mess_1,rb_mess_2,rb_hepatomegalia_1,rb_hepatomegalia_2,rb_splenoma_1,rb_splenoma_2,
	                    rb_shift_dullness_1,rb_shift_dullness_2,rb_lowerlimb_edema_1,rb_lowerlimb_edema_2,rb_lowerlimb_edema_3,rb_lowerlimb_edema_4,
	                    rb_dorsalfoot_rate_1,rb_dorsalfoot_rate_2,rb_dorsalfoot_rate_3,rb_dorsalfoot_rate_4,rb_anus_1,rb_anus_2,rb_anus_3,
	                    rb_anus_4,rb_anus_5,rb_vulva_1,rb_vulva_2,rb_vagina_1,rb_vagina_2,rb_cervix_1,rb_cervix_2,rb_palace_1,rb_palace_2,
	                    rb_appendix_1,rb_appendix_2,rb_ecg_1,rb_ecg_2,rb_fecal_occult_blood_1,rb_fecal_occult_blood_2;
	
	private CheckBox cb_mammary_gland_1,cb_mammary_gland_2,cb_mammary_gland_3,cb_mammary_gland_4,cb_mammary_gland_5;
	private HealthTest ht;
	private View child;
	
	public HealthTest_3(Context context,int profileId,int testId) {
		super(context);
		// TODO Auto-generated constructor stub
		//档案编号
		this.profileid = profileId;
		this.testid = testId;
		this.mContext = context;
		
		final LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.healthtest_3, null);
		
		
		//findViewsById();
		
		//initViews();
		
		
	}
	
	public int getProfileid() {
		return profileid;
	}

	public void setProfileid(int profileid) {
		this.profileid = profileid;
	}

	public int getTestid() {
		return testid;
	}

	public void setTestid(int testid) {
		this.testid = testid;
	}

	public void findViewsById() {
		// TODO Auto-generated method stub
		
		et_tenderness = (EditText)child.findViewById(R.id.ht3_tenderness);
		et_tenderness.setOnFocusChangeListener(this);
		et_tenderness.setOnClickListener(this);
		et_mess = (EditText)child.findViewById(R.id.ht3_mess);
		et_mess.setOnFocusChangeListener(this);
		et_mess.setOnClickListener(this);
		et_hepatomegalia = (EditText)child.findViewById(R.id.ht3_hepatomegalia);
		et_hepatomegalia.setOnFocusChangeListener(this);
		et_hepatomegalia.setOnClickListener(this);
		et_splenoma = (EditText)child.findViewById(R.id.ht3_splenoma);
		et_splenoma.setOnFocusChangeListener(this);
		et_splenoma.setOnClickListener(this);
		et_shift_dullness = (EditText)child.findViewById(R.id.ht3_shift_dullnes);
		et_shift_dullness.setOnFocusChangeListener(this);
		et_shift_dullness.setOnClickListener(this);
		et_anus_other = (EditText)child.findViewById(R.id.ht3_anus_other);
		et_anus_other.setOnFocusChangeListener(this);
		et_anus_other.setOnClickListener(this);
		et_mammary_gland_other = (EditText)child.findViewById(R.id.ht3_mammary_gland_other);
		et_mammary_gland_other.setOnFocusChangeListener(this);
		et_mammary_gland_other.setOnClickListener(this);
		et_vulva_abnormal = (EditText)child.findViewById(R.id.ht3_vulva);
		et_vulva_abnormal.setOnFocusChangeListener(this);
		et_vulva_abnormal.setOnClickListener(this);
		et_vagina_abnormal = (EditText)child.findViewById(R.id.ht3_vagina);
		et_vagina_abnormal.setOnFocusChangeListener(this);
		et_vagina_abnormal.setOnClickListener(this);
		et_cervix_abnormal = (EditText)child.findViewById(R.id.ht3_cervix);
		et_cervix_abnormal.setOnFocusChangeListener(this);
		et_cervix_abnormal.setOnClickListener(this);
		et_palace_abnormal = (EditText)child.findViewById(R.id.ht3_palace);
		et_palace_abnormal.setOnFocusChangeListener(this);
		et_palace_abnormal.setOnClickListener(this);
		et_appendix_abnormal = (EditText)child.findViewById(R.id.ht3_appendix);
		et_appendix_abnormal.setOnFocusChangeListener(this);
		et_appendix_abnormal.setOnClickListener(this);
		et_bodycheck_other = (EditText)child.findViewById(R.id.ht3_bodycheck_other);
        et_hemoglobin = (EditText)child.findViewById(R.id.ht3_hemoglobin);
        et_wbc = (EditText)child.findViewById(R.id.ht3_wbc);
        et_blood_platelet = (EditText)child.findViewById(R.id.ht3_blood_platelet);
        et_blood_other = (EditText)child.findViewById(R.id.ht3_blood_other);
        et_pro = (EditText)child.findViewById(R.id.ht3_pro);
        et_glu = (EditText)child.findViewById(R.id.ht3_glu);
        et_urine_ketone = (EditText)child.findViewById(R.id.ht3_urine_ketone);
        et_bld = (EditText)child.findViewById(R.id.ht3_bld);
        et_urine_other = (EditText)child.findViewById(R.id.ht3_urine_other);
        et_fbs_1 = (EditText)child.findViewById(R.id.ht3_fbs_1);
        et_fbs_2 = (EditText)child.findViewById(R.id.ht3_fbs_2);
        et_ecg = (EditText)child.findViewById(R.id.ht3_ecg);
        et_ecg.setOnFocusChangeListener(this);
        et_ecg.setOnClickListener(this);
        et_uae = (EditText)child.findViewById(R.id.ht3_uae);
        et_ghb = (EditText)child.findViewById(R.id.ht3_ghb);
		rb_tenderness_1 = (RadioButton)child.findViewById(R.id.ht3_tenderness_1);
		rb_tenderness_2 = (RadioButton)child.findViewById(R.id.ht3_tenderness_2);
		rb_mess_1 = (RadioButton)child.findViewById(R.id.ht3_mess_1);
		rb_mess_2 = (RadioButton)child.findViewById(R.id.ht3_mess_2);
		rb_hepatomegalia_1 = (RadioButton)child.findViewById(R.id.ht3_hepatomegalia_1);
		rb_hepatomegalia_2 = (RadioButton)child.findViewById(R.id.ht3_hepatomegalia_2);
		rb_splenoma_1 = (RadioButton)child.findViewById(R.id.ht3_splenoma_1);
		rb_splenoma_2 = (RadioButton)child.findViewById(R.id.ht3_splenoma_2);
        rb_shift_dullness_1 = (RadioButton)child.findViewById(R.id.ht3_shift_dullness_1);
        rb_shift_dullness_2 = (RadioButton)child.findViewById(R.id.ht3_shift_dullness_2);
        rb_lowerlimb_edema_1 = (RadioButton)child.findViewById(R.id.ht3_lowerlimb_edema_1);
        rb_lowerlimb_edema_2 = (RadioButton)child.findViewById(R.id.ht3_lowerlimb_edema_2);
        rb_lowerlimb_edema_3 = (RadioButton)child.findViewById(R.id.ht3_lowerlimb_edema_3);
        rb_lowerlimb_edema_4 = (RadioButton)child.findViewById(R.id.ht3_lowerlimb_edema_4);
        rb_dorsalfoot_rate_1 = (RadioButton)child.findViewById(R.id.ht3_dorsalfoot_rate_1);
        rb_dorsalfoot_rate_1.setOnClickListener(this);
        rb_dorsalfoot_rate_2 = (RadioButton)child.findViewById(R.id.ht3_dorsalfoot_rate_2);
        rb_dorsalfoot_rate_2.setOnClickListener(this);
        rb_dorsalfoot_rate_3 = (RadioButton)child.findViewById(R.id.ht3_dorsalfoot_rate_3);
        rb_dorsalfoot_rate_3.setOnClickListener(this);
        rb_dorsalfoot_rate_4 = (RadioButton)child.findViewById(R.id.ht3_dorsalfoot_rate_4);
        rb_dorsalfoot_rate_4.setOnClickListener(this);
        rb_anus_1 = (RadioButton)child.findViewById(R.id.ht3_anus_1);
        rb_anus_2 = (RadioButton)child.findViewById(R.id.ht3_anus_2);
        rb_anus_3 = (RadioButton)child.findViewById(R.id.ht3_anus_3);
        rb_anus_4 = (RadioButton)child.findViewById(R.id.ht3_anus_4);
        rb_anus_5 = (RadioButton)child.findViewById(R.id.ht3_anus_5);
        rb_vulva_1 = (RadioButton)child.findViewById(R.id.ht3_vulva_1);
        rb_vulva_2 = (RadioButton)child.findViewById(R.id.ht3_vulva_2);
        rb_vagina_1 = (RadioButton)child.findViewById(R.id.ht3_vagina_1);
        rb_vagina_2 = (RadioButton)child.findViewById(R.id.ht3_vagina_2);
        rb_cervix_1 = (RadioButton)child.findViewById(R.id.ht3_cervix_1);
        rb_cervix_2 = (RadioButton)child.findViewById(R.id.ht3_cervix_2);
        rb_appendix_1 = (RadioButton)child.findViewById(R.id.ht3_appendix_1);
        rb_appendix_2 = (RadioButton)child.findViewById(R.id.ht3_appendix_2);
        rb_ecg_1 = (RadioButton)child.findViewById(R.id.ht3_ecg_1);
        rb_ecg_2 = (RadioButton)child.findViewById(R.id.ht3_ecg_2);
        rb_fecal_occult_blood_1 = (RadioButton)child.findViewById(R.id.ht3_fecal_occult_blood_1);
        rb_fecal_occult_blood_2 = (RadioButton)child.findViewById(R.id.ht3_fecal_occult_blood_2);
		cb_mammary_gland_1 = (CheckBox)child.findViewById(R.id.ht3_mammary_gland_1);
		cb_mammary_gland_2 = (CheckBox)child.findViewById(R.id.ht3_mammary_gland_2);
		cb_mammary_gland_3 = (CheckBox)child.findViewById(R.id.ht3_mammary_gland_3);
		cb_mammary_gland_4 = (CheckBox)child.findViewById(R.id.ht3_mammary_gland_4);
		cb_mammary_gland_5 = (CheckBox)child.findViewById(R.id.ht3_mammary_gland_5);
		rb_palace_1 = (RadioButton)child.findViewById(R.id.ht3_palace_1);
		rb_palace_2 = (RadioButton)child.findViewById(R.id.ht3_palace_2);
		rgTenderness = (RadioGroup)child.findViewById(R.id.radioGroup18);
		rgMess = (RadioGroup)child.findViewById(R.id.radioGroup19);
		rgHepatomegalia = (RadioGroup)child.findViewById(R.id.radioGroup20);
		rgSplenoma = (RadioGroup)child.findViewById(R.id.radioGroup21);
		rgShiftDullness = (RadioGroup)child.findViewById(R.id.radioGroup22);
		rgLowerlimbEdema = (RadioGroup)child.findViewById(R.id.radioGroup23);
		rgAnus = (RadioGroup)child.findViewById(R.id.radioGroup25);
        rgVulva = (RadioGroup)child.findViewById(R.id.radioGroup26);
        rgVagina = (RadioGroup)child.findViewById(R.id.radioGroup27);
        rgCervix = (RadioGroup)child.findViewById(R.id.radioGroup28);
        rgPalace = (RadioGroup)child.findViewById(R.id.radioGroup29);
        rgAppendix = (RadioGroup)child.findViewById(R.id.radioGroup30);
        rgEcg = (RadioGroup)child.findViewById(R.id.radioGroup31);
        rgFecalOccultBlood = (RadioGroup)child.findViewById(R.id.radioGroup1);
		
	}
	
	/**
	 * 根据ID从数据库中读出数据并填充views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		
		initialState();
		
		String temp = "";
		int itemp = -1;
		float ftemp = -1f;
		
		itemp = ht.getHete_has_tenderness();
		switch(itemp){
		case 1:
			rgTenderness.check(0);
			rb_tenderness_1.setChecked(true);
			break;
		case 2:{
			rgTenderness.check(1);
			rb_tenderness_2.setChecked(true);
			temp = ht.getHete_tenderness();
			et_tenderness.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_has_mess();
		switch(itemp){
		case 1:
			rgMess.check(0);
			rb_mess_1.setChecked(true);
			break;
		case 2:{
			rgMess.check(1);
			rb_mess_2.setChecked(true);
			temp = ht.getHete_mess();
			et_mess.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_has_hepatomegalia();
		switch(itemp){
		case 1:
			rgHepatomegalia.check(0);
			rb_hepatomegalia_1.setChecked(true);
			break;
		case 2:{
			rgHepatomegalia.check(1);
			rb_hepatomegalia_2.setChecked(true);
			temp = ht.getHete_hepatomegalia();
			et_hepatomegalia.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_has_splenoma();
		switch(itemp){
		case 1:
			rgSplenoma.check(0);
			rb_splenoma_1.setChecked(true);
			break;
		case 2:{
			rgSplenoma.check(1);
			rb_splenoma_2.setChecked(true);
			temp = ht.getHete_splenoma();
			et_splenoma.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_has_shifting_dullness();
		switch(itemp){
		case 1:
			rgShiftDullness.check(0);
			rb_shift_dullness_1.setChecked(true);
			break;
		case 2:{
			rgShiftDullness.check(1);
			rb_shift_dullness_2.setChecked(true);
			temp = ht.getHete_shifting_dullness();
			et_shift_dullness.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_lowerlimb_edema();
		switch(itemp){
		case 1:
			rgLowerlimbEdema.check(0);
			rb_lowerlimb_edema_1.setChecked(true);
			break;
		case 2:
			rgLowerlimbEdema.check(1);
			rb_lowerlimb_edema_2.setChecked(true);
			break;
		case 3:
			rgLowerlimbEdema.check(2);
			rb_lowerlimb_edema_3.setChecked(true);
			break;
		case 4:
			rgLowerlimbEdema.check(3);
			rb_lowerlimb_edema_4.setChecked(true);
			break;
		}
		
		itemp = ht.getHete_dorsalfoot_artetial_pulse();
		switch(itemp){
		case 1:
			rb_dorsalfoot_rate_1.setChecked(true);
			break;
		case 2:
			rb_dorsalfoot_rate_2.setChecked(true);
			break;
		case 3:
			rb_dorsalfoot_rate_3.setChecked(true);
			break;
		case 4:
			rb_dorsalfoot_rate_4.setChecked(true);
			break;
		}
		
		itemp = ht.getHete_anus();
		switch(itemp){
		case 1:
			rgAnus.check(0);
			rb_anus_1.setChecked(true);
			break;
		case 2:
			rgAnus.check(1);
			rb_anus_2.setChecked(true);
			break;
		case 3:
			rgAnus.check(2);
			rb_anus_3.setChecked(true);
			break;
		case 4:
			rgAnus.check(3);
			rb_anus_4.setChecked(true);
			break;
		case 5:{
			rgAnus.check(4);
			rb_anus_5.setChecked(true);
			temp = ht.getHete_anus_other();
			et_anus_other.setText(temp);
			break;
		}
		}
		
		temp = ht.getHete_mammary_gland();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_mammary_gland_1.setChecked(true);
					break;
				case 2:
					cb_mammary_gland_2.setChecked(true);
					break;
				case 3:
					cb_mammary_gland_3.setChecked(true);
					break;
				case 4:
					cb_mammary_gland_4.setChecked(true);
					break;
				case 5:{
					cb_mammary_gland_5.setChecked(true);
					temp = ht.getHete_mammary_gland_other();
					et_mammary_gland_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = ht.getHete_vulva();
		switch(itemp){
		case 1:
			rgVulva.check(0);
			rb_vulva_1.setChecked(true);
			break;
		case 2:{
			rgVulva.check(1);
			rb_vulva_2.setChecked(true);
			temp = ht.getHete_vulva_abnormal();
			et_vulva_abnormal.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_vagina();
		switch(itemp){
		case 1:
			rgVagina.check(0);
			rb_vagina_1.setChecked(true);
			break;
		case 2:{
			rgVagina.check(1);
			rb_vagina_2.setChecked(true);
			temp = ht.getHete_vagina_abnormal();
			et_vagina_abnormal.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_cervix();
		switch(itemp){
		case 1:
			rgCervix.check(0);
			rb_cervix_1.setChecked(true);
			break;
		case 2:{
			rgCervix.check(1);
			rb_cervix_2.setChecked(true);
			temp = ht.getHete_cervix_abnormal();
			et_cervix_abnormal.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_palace();
		switch(itemp){
		case 1:
			rgPalace.check(0);
			rb_palace_1.setChecked(true);
			break;
		case 2:{
			rgPalace.check(1);
			rb_palace_2.setChecked(true);
			temp = ht.getHete_palace_abnormal();
			et_palace_abnormal.setText(temp);
			break;
		}
		}
		
		itemp = ht.getHete_appendix();
		switch(itemp){
		case 1:
			rgAppendix.check(0);
			rb_appendix_1.setChecked(true);
			break;
		case 2:{
			rgAppendix.check(1);
			rb_appendix_2.setChecked(true);
			temp = ht.getHete_appendix_abnormal();
			et_appendix_abnormal.setText(temp);
			break;
		}
		}
		
		temp = ht.getHete_bodycheck_other();
		et_bodycheck_other.setText(temp);
		
		ftemp = ht.getHete_hemoglobin();
		if(ftemp!=-1f){
			et_hemoglobin.setText(String.valueOf(ftemp));			
		}
		ftemp = ht.getHete_wbc();
		if(ftemp!=-1f){
			et_wbc.setText(String.valueOf(ftemp));			
		}
		ftemp = ht.getHete_blood_platelet();
		if(ftemp!=-1f){
			et_blood_platelet.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_blood_other();
		if(ftemp!=-1f){
			et_blood_other.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_pro();
		if(ftemp!=-1f){
			et_pro.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_glu();
		if(ftemp!=-1f){
			et_glu.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_urine_ketone();
		if(ftemp!=-1f){
			et_urine_ketone.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_bld();
		if(ftemp!=-1f){
			et_bld.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_urine_other();
		if(ftemp!=-1f){
			et_urine_other.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_fbs1();
		if(ftemp!=-1f){
			et_fbs_1.setText(String.valueOf(ftemp));
		}
		ftemp = ht.getHete_fbs2();
		if(ftemp!=-1f){
			et_fbs_2.setText(String.valueOf(ftemp));
		}
		
		itemp = ht.getHete_ecg();
		switch(itemp){
		case 1:
			rgEcg.check(0);
			rb_ecg_1.setChecked(true);
			break;
		case 2:{
			rgEcg.check(1);
			rb_ecg_2.setChecked(true);
			temp = ht.getHete_ecg_abnormal();
			et_ecg.setText(temp);
			break;
		}
		}

		ftemp = ht.getHete_uae();
		if(ftemp!=-1f){
			et_uae.setText(String.valueOf(ftemp));
		}
		
		itemp = ht.getHete_fecal_occult_blood();
		switch(itemp){
		case 1:
			rgFecalOccultBlood.check(0);
			rb_fecal_occult_blood_1.setChecked(true);
			break;
		case 2:
			rgFecalOccultBlood.check(1);
			rb_fecal_occult_blood_2.setChecked(true);
			break;
		}
		
		ftemp = ht.getHete_ghb();
		if(ftemp!=-1f){
			et_ghb.setText(String.valueOf(ftemp));
		}
	}
	
	/**
	 * 初始时为空表：横线为空，所有选择项未选中
	 */
	private void initialState() {
		// TODO Auto-generated method stub
		et_tenderness.setText("");
		et_mess.setText("");
		et_hepatomegalia.setText("");
		et_splenoma.setText("");
		et_shift_dullness.setText("");
		et_anus_other.setText("");
		et_mammary_gland_other.setText("");
		et_vulva_abnormal.setText("");
        et_vagina_abnormal.setText("");
        et_cervix_abnormal.setText("");
        et_palace_abnormal.setText("");
        et_appendix_abnormal.setText("");
        et_bodycheck_other.setText("");
        et_hemoglobin.setText("");
        et_wbc.setText("");
        et_blood_platelet.setText("");
        et_blood_other.setText("");
        et_pro.setText("");
        et_glu.setText("");
        et_urine_ketone.setText("");
        et_bld.setText("");
        et_urine_other.setText("");
        et_fbs_1.setText("");
        et_fbs_2.setText("");
        et_ecg.setText("");
        et_uae.setText("");
        et_ghb.setText("");
		rb_tenderness_1.setChecked(false);
		rb_tenderness_2.setChecked(false);
		rb_mess_1.setChecked(false);
		rb_mess_2.setChecked(false);
		rb_hepatomegalia_1.setChecked(false);
		rb_hepatomegalia_2.setChecked(false);
		rb_splenoma_1.setChecked(false);
		rb_splenoma_2.setChecked(false);
        rb_shift_dullness_1.setChecked(false);
        rb_shift_dullness_2.setChecked(false);
        rb_lowerlimb_edema_1.setChecked(false);
        rb_lowerlimb_edema_2.setChecked(false);
        rb_lowerlimb_edema_3.setChecked(false);
        rb_lowerlimb_edema_4.setChecked(false);
        rb_dorsalfoot_rate_1.setChecked(false);
        rb_dorsalfoot_rate_2.setChecked(false);
        rb_dorsalfoot_rate_3.setChecked(false);
        rb_dorsalfoot_rate_4.setChecked(false);
        rb_anus_1.setChecked(false);
        rb_anus_2.setChecked(false);
        rb_anus_3.setChecked(false);
        rb_anus_4.setChecked(false);
        rb_anus_5.setChecked(false);
        rb_vulva_1.setChecked(false);
        rb_vulva_2.setChecked(false);
        rb_vagina_1.setChecked(false);
        rb_vagina_2.setChecked(false);
        rb_cervix_1.setChecked(false);
        rb_cervix_2.setChecked(false);
        rb_palace_1.setChecked(false);
        rb_palace_2.setChecked(false);
        rb_appendix_1.setChecked(false);
        rb_appendix_2.setChecked(false);
        rb_ecg_1.setChecked(false);
        rb_ecg_2.setChecked(false);
        rb_fecal_occult_blood_1.setChecked(false);
        rb_fecal_occult_blood_2.setChecked(false);
		cb_mammary_gland_1.setChecked(false);
		cb_mammary_gland_2.setChecked(false);
		cb_mammary_gland_3.setChecked(false);
		cb_mammary_gland_4.setChecked(false);
		cb_mammary_gland_5.setChecked(false);
	}

	/**
	 * 添加view到contentview
	 */
	public void setMyView(){
		this.removeAllViews();
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(child,lp);	
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return this.child;
	}
	
	/**
	 * 检出数据
	 */
	public void fetchData(){
		ht = new HealthTest(mContext);
		ht.selectHealthTest(this.profileid,this.testid);
		
	}
	
	
	/**
	 * 读取views的值并保存至ID对应的记录中
	 */
	public void saveViews() {
		HealthTest ht = new HealthTest(mContext);
		ht.selectHealthTest(profileid, testid);
		String temp = "";
		StringBuffer sb = new StringBuffer();
//		int itemp = -1;
//		float ftemp = -1.0f;
		
		if(rb_tenderness_1.isChecked()==true){
			ht.setHete_has_tenderness(1);
		}else if(rb_tenderness_2.isChecked()==true){
			ht.setHete_has_tenderness(2);
			temp = et_tenderness.getText().toString();
			ht.setHete_tenderness(temp);
		}
		if(rb_mess_1.isChecked()==true){
			ht.setHete_has_mess(1);
		}else if(rb_mess_2.isChecked()==true){
			ht.setHete_has_mess(2);
			temp = et_mess.getText().toString();
			ht.setHete_mess(temp);
		}
		if(rb_hepatomegalia_1.isChecked()==true){
			ht.setHete_has_hepatomegalia(1);
		}else if(rb_hepatomegalia_2.isChecked()==true){
			ht.setHete_has_hepatomegalia(2);
			temp = et_hepatomegalia.getText().toString();
			ht.setHete_hepatomegalia(temp);
		}
		if(rb_splenoma_1.isChecked()==true){
			ht.setHete_has_splenoma(1);
		}else if(rb_splenoma_2.isChecked()==true){
			ht.setHete_has_splenoma(2);
			temp = et_splenoma.getText().toString();
			ht.setHete_splenoma(temp);
		}
		if(rb_shift_dullness_1.isChecked()==true){
			ht.setHete_has_shifting_dullness(1);
		}else if(rb_shift_dullness_2.isChecked()==true){
			ht.setHete_has_shifting_dullness(2);
			temp = et_shift_dullness.getText().toString();
			ht.setHete_shifting_dullness(temp);
		}
		
		if(rb_lowerlimb_edema_1.isChecked()==true){
			ht.setHete_lowerlimb_edema(1);
		}else if(rb_lowerlimb_edema_2.isChecked()==true){
			ht.setHete_lowerlimb_edema(2);
		}else if(rb_lowerlimb_edema_3.isChecked()==true){
			ht.setHete_lowerlimb_edema(3);
		}else if(rb_lowerlimb_edema_4.isChecked()==true){
			ht.setHete_lowerlimb_edema(4);
		}
		
		if(rb_dorsalfoot_rate_1.isChecked()==true){
			ht.setHete_dorsalfoot_artetial_pulse(1);
		}else if(rb_dorsalfoot_rate_2.isChecked()==true){
			ht.setHete_dorsalfoot_artetial_pulse(2);
		}else if(rb_dorsalfoot_rate_3.isChecked()==true){
			ht.setHete_dorsalfoot_artetial_pulse(3);
		}else if(rb_dorsalfoot_rate_4.isChecked()==true){
			ht.setHete_dorsalfoot_artetial_pulse(4);
		}
		
		if(rb_anus_1.isChecked()==true){
			ht.setHete_anus(1);
		}else if(rb_anus_2.isChecked()==true){
			ht.setHete_anus(2);
		}else if(rb_anus_3.isChecked()==true){
			ht.setHete_anus(3);
		}else if(rb_anus_4.isChecked()==true){
			ht.setHete_anus(4);
		}else if(rb_anus_5.isChecked()==true){
			ht.setHete_anus(5);
			temp = et_anus_other.getText().toString();
			ht.setHete_anus_other(temp);
		}
		
		if(cb_mammary_gland_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_mammary_gland_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_mammary_gland_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_mammary_gland_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_mammary_gland_5.isChecked()==true){
			sb.append("5,");
			temp = et_mammary_gland_other.getText().toString();
			ht.setHete_mammary_gland_other(temp);
		}
		ht.setHete_mammary_gland(sb.toString());
		
		if(rb_vulva_1.isChecked()==true){
			ht.setHete_vulva(1);
		}else if(rb_vulva_2.isChecked()==true){
			ht.setHete_vulva(2);
			temp = et_vulva_abnormal.getText().toString();
			ht.setHete_vulva_abnormal(temp);
		}
		if(rb_vagina_1.isChecked()==true){
			ht.setHete_vagina(1);
		}else if(rb_vagina_2.isChecked()==true){
			ht.setHete_vagina(2);
			temp = et_vagina_abnormal.getText().toString();
			ht.setHete_vagina_abnormal(temp);
		}
		if(rb_cervix_1.isChecked()==true){
			ht.setHete_cervix(1);
		}else if(rb_cervix_2.isChecked()==true){
			ht.setHete_cervix(2);
			temp = et_cervix_abnormal.getText().toString();
			ht.setHete_cervix_abnormal(temp);
		}
		if(rb_palace_1.isChecked()==true){
			ht.setHete_palace(1);
		}else if(rb_palace_2.isChecked()==true){
			ht.setHete_palace(2);
			temp = et_palace_abnormal.getText().toString();
			ht.setHete_palace_abnormal(temp);
		}
		if(rb_appendix_1.isChecked()==true){
			ht.setHete_appendix(1);
		}else if(rb_appendix_2.isChecked()==true){
			ht.setHete_appendix(2);
			temp = et_appendix_abnormal.getText().toString();
			ht.setHete_appendix_abnormal(temp);
		}
		
		temp = et_bodycheck_other.getText().toString();
		ht.setHete_bodycheck_other(temp);
		
		temp = et_hemoglobin.getText().toString();
		if(temp.length()>0){
			ht.setHete_hemoglobin(Float.parseFloat(temp));
		}
		temp = et_wbc.getText().toString();
		if(temp.length()>0){
			ht.setHete_wbc(Float.parseFloat(temp));
		}
		temp = et_blood_platelet.getText().toString();
		if(temp.length()>0){
			ht.setHete_blood_platelet(Float.parseFloat(temp));
		}
		temp = et_blood_other.getText().toString();
		if(temp.length()>0){
			ht.setHete_blood_other(Float.parseFloat(temp));
		}
		temp = et_pro.getText().toString();
		if(temp.length()>0){
			ht.setHete_pro(Float.parseFloat(temp));
		}
		temp = et_glu.getText().toString();
		if(temp.length()>0){
			ht.setHete_glu(Float.parseFloat(temp));
		}
		temp = et_urine_ketone.getText().toString();
		if(temp.length()>0){
			ht.setHete_urine_ketone(Float.parseFloat(temp));
		}
		temp = et_bld.getText().toString();
		if(temp.length()>0){
			ht.setHete_bld(Float.parseFloat(temp));
		}
		temp = et_urine_other.getText().toString();
		if(temp.length()>0){
			ht.setHete_urine_other(Float.parseFloat(temp));
		}
		temp = et_fbs_1.getText().toString();
		if(temp.length()>0){
			ht.setHete_fbs1(Float.parseFloat(temp));
		}
		temp = et_fbs_2.getText().toString();
		if(temp.length()>0){
			ht.setHete_fbs2(Float.parseFloat(temp));
		}
		
		if(rb_ecg_1.isChecked()==true){
			ht.setHete_ecg(1);
		}else if(rb_ecg_2.isChecked()==true){
			ht.setHete_ecg(2);
			temp = et_ecg.getText().toString();
			ht.setHete_ecg_abnormal(temp);
		}

		temp = et_uae.getText().toString();
		if(temp.length()>0){
			ht.setHete_uae(Float.parseFloat(temp));
		}
		
		if(rb_fecal_occult_blood_1.isChecked()==true){
			ht.setHete_fecal_occult_blood(1);
		}else if(rb_fecal_occult_blood_2.isChecked()==true){
			ht.setHete_fecal_occult_blood(2);
		}
		
		temp = et_ghb.getText().toString();
		if(temp.length()>0){
			ht.setHete_ghb(Float.parseFloat(temp));
		}
		
		ht.updateHealthTest(this.profileid,this.testid);
		
	}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==rb_dorsalfoot_rate_1){
			rb_dorsalfoot_rate_1.setChecked(true);
			rb_dorsalfoot_rate_2.setChecked(false);
			rb_dorsalfoot_rate_3.setChecked(false);
			rb_dorsalfoot_rate_4.setChecked(false);
		}
		else if(v==rb_dorsalfoot_rate_2){
			rb_dorsalfoot_rate_1.setChecked(false);
			rb_dorsalfoot_rate_2.setChecked(true);
			rb_dorsalfoot_rate_3.setChecked(false);
			rb_dorsalfoot_rate_4.setChecked(false);
		}
		else if(v==rb_dorsalfoot_rate_3){
			rb_dorsalfoot_rate_1.setChecked(false);
			rb_dorsalfoot_rate_2.setChecked(false);
			rb_dorsalfoot_rate_3.setChecked(true);
			rb_dorsalfoot_rate_4.setChecked(false);
		}
		else if(v==rb_dorsalfoot_rate_4){
			rb_dorsalfoot_rate_1.setChecked(false);
			rb_dorsalfoot_rate_2.setChecked(false);
			rb_dorsalfoot_rate_3.setChecked(false);
			rb_dorsalfoot_rate_4.setChecked(true);
		}
		else if(v==et_tenderness){
			rb_tenderness_1.setChecked(false);
			rb_tenderness_2.setChecked(true);
		}
		else if(v==et_mess){
			rb_mess_1.setChecked(false);
			rb_mess_2.setChecked(true);
		}
		else if(v==et_hepatomegalia){
			rb_hepatomegalia_1.setChecked(false);
			rb_hepatomegalia_2.setChecked(true);
		}
		else if(v==et_splenoma){
			rb_splenoma_1.setChecked(false);
			rb_splenoma_2.setChecked(true);
		}
		else if(v==et_shift_dullness){
			rb_shift_dullness_1.setChecked(false);
			rb_shift_dullness_2.setChecked(true);
		}
		else if(v==et_anus_other){
			rb_anus_1.setChecked(false);
			rb_anus_2.setChecked(false);
			rb_anus_3.setChecked(false);
			rb_anus_4.setChecked(false);
			rb_anus_5.setChecked(true);
		}
		else if(v==et_mammary_gland_other){
			cb_mammary_gland_5.setChecked(true);
		}
		else if(v==et_vulva_abnormal){
			rb_vulva_1.setChecked(false);
			rb_vulva_2.setChecked(true);
		}
		else if(v==et_vagina_abnormal){
			rb_vagina_1.setChecked(false);
			rb_vagina_2.setChecked(true);
		}
		else if(v==et_cervix_abnormal){
			rb_cervix_1.setChecked(false);
			rb_cervix_2.setChecked(true);
		}
		else if(v==et_palace_abnormal){
			rb_palace_1.setChecked(false);
			rb_palace_2.setChecked(true);
		}
		else if(v==et_appendix_abnormal){
			rb_appendix_1.setChecked(false);
			rb_appendix_2.setChecked(true);
		}
		else if(v==et_ecg){
			rb_ecg_1.setChecked(false);
			rb_ecg_2.setChecked(true);
		}
		
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(hasFocus){
			if(v==et_tenderness){
				rb_tenderness_1.setChecked(false);
				rb_tenderness_2.setChecked(true);
			}
			else if(v==et_mess){
				rb_mess_1.setChecked(false);
				rb_mess_2.setChecked(true);
			}
			else if(v==et_hepatomegalia){
				rb_hepatomegalia_1.setChecked(false);
				rb_hepatomegalia_2.setChecked(true);
			}
			else if(v==et_splenoma){
				rb_splenoma_1.setChecked(false);
				rb_splenoma_2.setChecked(true);
			}
			else if(v==et_shift_dullness){
				rb_shift_dullness_1.setChecked(false);
				rb_shift_dullness_2.setChecked(true);
			}
			else if(v==et_anus_other){
				rb_anus_1.setChecked(false);
				rb_anus_2.setChecked(false);
				rb_anus_3.setChecked(false);
				rb_anus_4.setChecked(false);
				rb_anus_5.setChecked(true);
			}
			else if(v==et_mammary_gland_other){
				cb_mammary_gland_5.setChecked(true);
			}
			else if(v==et_vulva_abnormal){
				rb_vulva_1.setChecked(false);
				rb_vulva_2.setChecked(true);
			}
			else if(v==et_vagina_abnormal){
				rb_vagina_1.setChecked(false);
				rb_vagina_2.setChecked(true);
			}
			else if(v==et_cervix_abnormal){
				rb_cervix_1.setChecked(false);
				rb_cervix_2.setChecked(true);
			}
			else if(v==et_palace_abnormal){
				rb_palace_1.setChecked(false);
				rb_palace_2.setChecked(true);
			}
			else if(v==et_appendix_abnormal){
				rb_appendix_1.setChecked(false);
				rb_appendix_2.setChecked(true);
			}
			else if(v==et_ecg){
				rb_ecg_1.setChecked(false);
				rb_ecg_2.setChecked(true);
			}
		}
	}

}
